#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
     HANDLE console = GetStdHandle(STD_INPUT_HANDLE);
     DWORD mode;
     GetConsoleMode(console, &mode);
     SetConsoleMode(console, mode & ~ENABLE_LINE_INPUT);

	 char answer;
	 int ammo;
	 bool pissed;

startGame:
	 ammo = 1;
	 pissed = false;


	 //		  01234567890123456789012345678901234567890123456789012345678901234567890123456789
describe_encounter:
	 cout << "You are a hunter, walking around the woods when you see a bear" << endl;
	 cout << "Startled by the sight of the bear, you accidentally alert it" << endl;
	 cout << "to your presence" << endl;
	 cout << endl;
	 cout << "The bear looks at you and gives a menacing growl" << endl;
	 cout << "What do you do?" << endl;
	 cout << "Do you -" << endl;
	 goto decision;
	 
decision:
	 cout << endl;
	 cout << "(s) Stand your Ground" << endl;
	 cout << "(c) Climb up the nearest tree" << endl;
	 cout << "(b) Draw your bow and attack the bear" << endl;
	 cout << "(r) Run away" << endl;

	 cin >> answer;

     if (answer == 's' && !pissed)
	 {
		goto describe_standYourGround;
	 }
	 else if (answer == 's' && pissed)
	 {
		goto describe_getMauled;
	 }
     else if (answer == 'c') 
	 {
		goto describe_climbUpTree;
	 }
	 else if (answer == 'b' && ammo == 1) 
	 {
		goto describe_shoot;
	 }
	 else if (answer == 'b' && ammo == 0) 
	 {
		goto noAmmo;
	 }
	 else if (answer == 'r')
	 {
		goto describe_tooLate;
	 }
     else
	 {
		goto unknown_encounter;
	 }
	 

unknown_encounter:
	 cout << endl;
     cout << "I did not understand" << endl;
     cout << endl;
     goto decision;

unknown_standYourGround:
	 cout << endl;
     cout << "I did not understand" << endl;
     cout << endl;
     goto standYourGroundDecision;

unknown_climbUpTree:
	 cout << endl;
     cout << "I did not understand" << endl;
     cout << endl;
     goto treeDecision;

noAmmo:
	 cout << endl;
	 cout << "You have no ammo!" << endl;
	 goto decision;

describe_shoot:
	 ammo = 0;
	 pissed = true;
	 cout << endl;
	 cout << "You draw your bow and shoot the bear." << endl;
	 cout << "Sadly it isn't your best shot, and the bear looks" << endl;
	 cout << "seriously pissed off! What do you do now?" << endl;
	 goto decision;

describe_standYourGround:
	 cout << endl;
	 cout << "The bear moves closer and gives another menacing growl" << endl;
	 cout << "It looks well peeved!" << endl;
	 
standYourGroundDecision:
	 cout << endl;
	 cout << "(s) Keep Standing your Ground" << endl;
	 cout << "(r) Roar back at the bear" << endl;
	 cout << "(b) Draw your bow and attack the bear" << endl;

	 cin >> answer;

     if (answer == 's')
	 {
		 goto describe_getMauled;
	 }
	 else if (answer == 'r')
	 {
		 cout << endl;
		 cout << "You let out a loud roar and the bear seems to cower a little." << endl;
		 cout << "Deciding you are one scary hombre, the bear turns and leaves." << endl;
		 cout << endl;
		 cout << "Good Job! You survived the bear encounter" << endl;
		 cout << "and didn't resort to violence! Well done!" << endl;
		 goto the_end;
	 }
	 else if (answer == 'b')
	 {
		 goto describe_tooLate;
	 }
     else
	 {
		 goto unknown_standYourGround;
	 }

describe_climbUpTree:
	 cout << endl;
	 cout << "You quickly climb the tree. The bear moves closer as you climb," << endl;
	 cout << "but you manage to get to a high branch before it reaches you." << endl;
	 cout << "As a hunter you know bears are rather good at getting up trees." << endl;
	 goto treeDecision;

treeDecision:
	 cout << endl;
	 cout << "What do you do now?" << endl;
	 cout << endl;
	 cout << "(s) Stay up in the tree and hope it goes away eventually" << endl;
	 cout << "(r) Roar down at the bear" << endl;
	 cout << "(b) Draw your bow and attack the bear" << endl;

	 cin >> answer;

     if (answer == 's' && !pissed)
	 {
		 cout << endl;
		 cout << "As you stay up in the tree luckily the bear does not" << endl;
		 cout << "decide to come after you. Eventually it leaves." << endl;
		 cout << endl;
		 cout << "Good Job! You survived the bear encounter" << endl;
		 cout << "and didn't resort to violence! Well done!" << endl;
		 goto the_end;
	 }
	 else if (answer == 's' && pissed)
	 {
		 cout << endl;
		 cout << "Unfortunately the bear quickly climbs the tree and gets you!" << endl;
		 cout << endl;
		 cout << "You get mauled!" << endl;
		 goto the_end;
	 }
	 else if (answer == 'r' && !pissed)
	 {
		 cout << endl;
		 cout << "The bear gets scared by your roar and leaves! Result! :-D" << endl;
		 cout << endl;
		 cout << "Good Job! You survived the bear encounter" << endl;
		 cout << "and didn't resort to violence! Well done!" << endl;
		 goto the_end;
	 }
	 else if (answer == 'r' && pissed)
	 {
		 cout << endl;
		 cout << "Unfortunately the bear quickly climbs the tree and gets you!" << endl;
		 cout << endl;
		 cout << "You get mauled!" << endl;
		 goto the_end;
	 }
	 else if (answer == 'b' && ammo == 1)
	 {
		 cout << endl;
		 cout << "You draw your bow and shoot the bear. It's a nice shot too!" << endl;
		 cout << "The bear falls to its side and lies defeated." << endl;
		 cout << endl;
		 cout << "Good Job! You survived the bear encounter" << endl;
		 goto the_end;
	 }
	 else if (answer == 'b' && ammo == 0)
	 {
		 cout << endl;
		 cout << "You have no ammo!" << endl;
		 goto treeDecision;
	 }
	 else
	 {
		 goto unknown_climbUpTree;
	 }


describe_tooLate:
	 cout << endl;
	 cout << "Too Late! As you try to perform your action, the bear charges" << endl;
	 cout << "towards you and knocks you to the ground." << endl;
	 cout << endl;
	 cout << "You meet a grizzly fate. :-P" << endl;
	 goto the_end;

describe_getMauled:
	 cout << endl;
	 cout << "Sadly your pacifism didn't pay off. The bear charges" << endl;
	 cout << "towards you and knocks you to the ground." << endl;
	 cout << endl;
	 cout << "You meet a grizzly fate. :-P" << endl;
	 goto the_end;
	 
the_end:
     cout << "The end." << endl;

restart_or_quit:
	 cout << endl;
     cout << "[r] Restart this game." << endl;
     cout << "[q] Quit." << endl;
     cout << endl;
     cout << ">";

     cin >> answer;

     switch (answer)
	 {
		 case 'r':
			 goto startGame;
			 break;

		 case 'q':
			 goto quit;

		 default:
			 goto restart_or_quit;
	 }

quit:
	 return 0;
}